<template>
  <el-button type="text" @click="gotoUrl">{{ text }}</el-button>
</template>

<script>
import { mapState } from "vuex";
import { canGotoUrl } from "@/utils";

export default {
  name: "LinkButton",
  props: {
    url: String,
    text: String,
  },
  methods: {
    gotoUrl() {
      if (
        canGotoUrl("/" + this.url, {
          readStr: this.READING_TIME,
          startAnswerStr: this.START_ANSWER_TIME,
          endAnswerStr: this.END_ANSWER_TIME,
        })
      ) {
        this.$router.push({
          name: this.url,
        });
      } else {
        this.$message({
          type: "warning",
          message: "目前不能跳转页面，请稍后再试",
        });
      }
    },
  },
  computed: {
    ...mapState(["READING_TIME", "START_ANSWER_TIME", "END_ANSWER_TIME"]),
  },
};
</script>
